﻿using TTSIDAL;
using TTSModel;
using System.Collections.Generic;

namespace TTSBLL
{
    public class UnitType : BaseService<UnitTypeInfo>
    {
        private static readonly IUnitType dal = DALFactory.TTS_DataAccess.CreateUnitType();

        public override void SetCurrentRepository()
        {
            CurrentRepository = dal;
        }

        public UnitTypeInfo UnitType_GetbyTcode(string tcode)
        {
            return dal.UnitType_GetbyTcode(tcode);
        }
        public IList<UnitTypeInfo> LoadEntities(string tcode)
        {
            return dal.LoadEntities(tcode);
        }
          public string GetTwoNewRecord(string tcode)
        {
            return dal.GetTwoNewRecord(tcode)[2].TcodeVersion+ "," +dal.GetTwoNewRecord(tcode)[1].TcodeVersion + "," + dal.GetTwoNewRecord(tcode)[0].TcodeVersion;
        }
         /* public string GetRandomVersion(int versionNum, string tcode)
          {
              return dal.GetRandomVersion(versionNum, tcode)[2].TcodeVersion + "," + dal.GetRandomVersion(versionNum, tcode)[1].TcodeVersion + "," + dal.GetRandomVersion(versionNum, tcode)[0].TcodeVersion;
          }*/
         public string GetRandomVersion(int versionNum, string tcode)
          {
              IList<UnitTypeInfo> unitList = dal.GetRandomVersion(versionNum, tcode);
              string stringAdd=null;
             for(int i=unitList.Count-1;i>=0;i--)
             {
                 stringAdd = stringAdd + unitList[i].TcodeVersion + ",";
             }
             return stringAdd.Substring(0,stringAdd.Length-1);
          }
         public string GetAllVersion(string tcode)
         {
             IList<UnitTypeInfo> unitList = dal.GetAllVersion(tcode);
             string stringAdd = null;
             for (int i = unitList.Count - 1; i >= 0; i--)
             {
                 stringAdd = stringAdd + unitList[i].TcodeVersion + ",";
             }
             return stringAdd.Substring(0, stringAdd.Length - 1);
         }
    }
}
